package MainUI;

import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;

public class LowerColumnUI {
    //设置主界面下框
    private static Label labelDataInformation = new Label();
    //下栏
    private static BorderPane borderPaneLowerColumn = new BorderPane();
    //当前选中文件的大小
    private static double imagePictureChoiceSize = 0;


    public LowerColumnUI() {
        //设置下栏
        labelDataInformation.setText(" " + PreviewInterfaceUI.getNumOfImage() + "张图片(" + PreviewInterfaceUI.getSizeOfImage() + " MB) - 选中" + PreviewInterfaceUI.getChoicePictureNum() + "张图片(" + getImagePictureChoiceSize() + " MB)");
        borderPaneLowerColumn.setLeft(labelDataInformation);
        labelDataInformation.setStyle("-fx-text-fill:black");
        borderPaneLowerColumn.setStyle("-fx-background-color:#fec5c9");

    }

    public static BorderPane getBorderPaneLowerColumn() {
        return borderPaneLowerColumn;
    }

    public void setBorderPaneLowerColumn(BorderPane borderPaneLowerColumn) {
        this.borderPaneLowerColumn = borderPaneLowerColumn;
    }

    public static Label getLabelDataInformation() {
        return labelDataInformation;
    }

    public static void setLabelDataInformation(Label labelDataInformation) {
        LowerColumnUI.labelDataInformation = labelDataInformation;
    }

    public static void setLabelDataInformationText() {
        if (PreviewInterfaceUI.getSizeOfImage() < 1024) {
            String strSize = String.format("%.2f", PreviewInterfaceUI.getSizeOfImage());
            double choiceSize = getImagePictureChoiceSize();
            String shrSize = String.format("%.2f", choiceSize);
            getLabelDataInformation().setText(" " + PreviewInterfaceUI.getNumOfImage() + "张图片(" + strSize + " KB) - 选中" + PreviewInterfaceUI.getChoicePictureNum() + "张图片(" + shrSize + " KB)");
        } else {
            double size = PreviewInterfaceUI.getSizeOfImage() / 1024;
            String strSize = String.format("%.2f", size);
            double choiceSize = getImagePictureChoiceSize();
            if (choiceSize >= 1024) {
                choiceSize = choiceSize / 1024.0;
                String shrSize = String.format("%.2f", choiceSize);
                getLabelDataInformation().setText(" " + PreviewInterfaceUI.getNumOfImage() + "张图片(" + strSize + " MB) - 选中" + PreviewInterfaceUI.getChoicePictureNum() + "张图片(" + shrSize + " MB)");
                return;
            }
            String shrSize = String.format("%.2f", choiceSize);
            getLabelDataInformation().setText(" " + PreviewInterfaceUI.getNumOfImage() + "张图片(" + strSize + " MB) - 选中" + PreviewInterfaceUI.getChoicePictureNum() + "张图片(" + shrSize + " KB)");
        }
    }

    public static double getImagePictureChoiceSize() {
        if (PreviewInterfaceUI.getArrayListImageFileChoice().isEmpty()) {
            LowerColumnUI.setImagePictureChoiceSize(0);
        } else {
            int length = PreviewInterfaceUI.getArrayListImageFileChoice().size();
            double size = 0;
            for (int i = 0; i < length; i++) {
                size = size + PreviewInterfaceUI.getArrayListImageFileChoice().get(i).length() / 1024.0;
            }
            LowerColumnUI.setImagePictureChoiceSize(size);
        }
        return imagePictureChoiceSize;
    }

    public static void setImagePictureChoiceSize(double imagePictureChoiceSize) {
        LowerColumnUI.imagePictureChoiceSize = imagePictureChoiceSize;
    }
}